package com.seari.controller;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seari.bean.DataGridBean;
import com.seari.bean.ImgProgress;
import com.seari.bean.QueryProBean;
import com.seari.main.StartUpClass;
import com.seari.pojo.ProRatePojo;
import com.seari.service.ImgProgressService;

@Controller
@RequestMapping("/imgProgress")
public class ImgProgressController {

	@Autowired
	private ImgProgressService imgProgressService;

	/**
	 * @param imgProgress
	 * @return 形象进度合同数
	 */
	@RequestMapping("proRate")
	@ResponseBody
	public DataGridBean<ImgProgress> proRate(@RequestBody(required = false) QueryProBean queryProBean) {
		DataGridBean<ImgProgress> grid = new DataGridBean<ImgProgress>();
		String proRate = StartUpClass.proRate;
		if (proRate.equals("pms")) {
			
			if (StringUtils.isNotBlank(queryProBean.getProId())) {

				List<ProRatePojo> proRateList = imgProgressService.queryRateConByProid(queryProBean);
				grid.setData(proRateList);
				grid.setCode("succee");

			} else if ( queryProBean.getConIdList() !=  null) {

				List<ProRatePojo> proRateList = imgProgressService.queryConRateByConid(queryProBean);
				grid.setData(proRateList);
				grid.setCode("succee");

			} else if (StringUtils.isNotBlank(queryProBean.getConTemplateId())) {
				
				List<ProRatePojo> proRateList = imgProgressService.queryTemplateRateByTemid(queryProBean);
				grid.setData(proRateList);
				grid.setCode("succee");


			} else {

				grid.setCode("err");
				grid.setMsg("参数不能为空!");
				return grid;

			}

		} else if (proRate.equals("sap")) {

		}
		return grid;
	}

	@RequestMapping("imgProgressInit")
	@ResponseBody
	public DataGridBean<ImgProgress> imgProgressInit(ImgProgress imgProgress) {
		DataGridBean<ImgProgress> dataGridBean = new DataGridBean<ImgProgress>();
		String imgProgressInit = StartUpClass.proRate;
		if (imgProgressInit.equals("sap")) {

		} else if (imgProgressInit.equals("pms")) {
			List<ImgProgress> imgProgresses = imgProgressService.imgProgressInit(imgProgress);
			int count = imgProgressService.imgProgressNumCount(imgProgress);
			dataGridBean.setRows(imgProgresses);
			dataGridBean.setTotal(count);
			dataGridBean.setCode("200");
		}
		return dataGridBean;
	}

	@RequestMapping("imgProgressCount")
	@ResponseBody
	public DataGridBean<ImgProgress> imgProgressCount(ImgProgress imgProgress) {
		DataGridBean<ImgProgress> dataGridBean = new DataGridBean<ImgProgress>();

		String imgProgressCount = StartUpClass.imgProgressCount;
		if (imgProgressCount.equals("sap")) {

		} else if (imgProgressCount.equals("pms")) {
			int count = imgProgressService.imgProgressNumCount(imgProgress);
			dataGridBean.setTotal(count);
			dataGridBean.setCode("200");
		}
		return dataGridBean;
	}

	/**
	 * 投资数偏差说明
	 * 
	 * @param imgProgress
	 * @return
	 */
	@RequestMapping("queryCapDeviationByProid")
	@ResponseBody
	public DataGridBean<ImgProgress> queryCapDeviationByProid(@RequestBody ImgProgress imgProgress) {
		DataGridBean<ImgProgress> dataGridBean = new DataGridBean<ImgProgress>();

		String queryCapDeviationByProid = StartUpClass.queryCapDeviationByProid;
		if (queryCapDeviationByProid.equals("pms")) {
			Map<String, List<String>> result = imgProgressService.queryCapDeviationByProid(imgProgress.getProId());
			dataGridBean.setData(result);
			dataGridBean.setTotal(result.size());
			dataGridBean.setCode("200");
		} else if (queryCapDeviationByProid.equals("sap")) {

		}

		return dataGridBean;
	}

	/**
	 * 资金数偏差说明
	 * 
	 * @param imgProgress
	 * @return
	 */
	@RequestMapping("queryInvDeviationByProid")
	@ResponseBody
	public DataGridBean<ImgProgress> queryInvDeviationByProid(@RequestBody ImgProgress imgProgress) {
		DataGridBean<ImgProgress> dataGridBean = new DataGridBean<ImgProgress>();

		String queryInvDeviationByProid = StartUpClass.queryInvDeviationByProid;
		if (queryInvDeviationByProid.equals("pms")) {
			Map<String, List<String>> result = imgProgressService.queryInvDeviationByProid(imgProgress.getProId());
			dataGridBean.setData(result);
			dataGridBean.setTotal(result.size());
			dataGridBean.setCode("200");
		} else if (queryInvDeviationByProid.equals("sap")) {

		}
		return dataGridBean;
	}

}
